import random


class Sweet():
    def __init__(self, arrlen):
        self.arrlen = arrlen
        self.arr = []

    def random_int(self):
        for i in range(self.arrlen):
            self.arr.append(random.randint(0, 99))

    def method_choice(self, should_method, *args, **kwargs):
        print(self.arr)
        should_method(*args,**kwargs)
        print(self.arr)

    def bubble_sort(self):
        arr = self.arr
        i = self.arrlen - 1
        while i > 0:
            j = 0
            flag = 1
            while j < i:
                if arr[j] > arr[j + 1]:
                    arr[j], arr[j + 1] = arr[j + 1], arr[j]
                    flag = 0
                j += 1
            if flag:
                break
            i -= 1

    def selection_sort(self):
        arr = self.arr
        i = 0
        while i < self.arrlen:
            min_pos = i
            j = i + 1
            while j < self.arrlen:
                if arr[j] < arr[min_pos]:
                    min_pos = j
                j += 1
            arr[i], arr[min_pos] = arr[min_pos], arr[i]
            i += 1

    def insertion_sort(self):
        arr = self.arr
        i = 1
        while i < self.arrlen:
            j = i - 1
            int_val = arr[i]
            while j >= 0 and arr[j]>=int_val:
                arr[j+1] = arr[j]
                j-=1
            arr[j+1] = int_val
            i+=1

    def shell_sort(self):
        arr = self.arr
        gap = self.arrlen >> 1
        while gap>0:
            i = gap
            while i < self.arrlen:
                j = i - gap
                int_val = arr[i]
                while j >= 0 and arr[j] >= int_val:
                    arr[j +gap] = arr[j]
                    j -= gap
                arr[j + gap] = int_val
                i += 1
            gap>>=1

    def partition_sort(self,left,right):
        arr = self.arr
        i = left
        k = left
        while i<right:
            if arr[i] < arr[right]:
                arr[i],arr[k] = arr[k],arr[i]
                k+=1
            i+=1
        arr[k], arr[right] = arr[right], arr[k]
        return k

    def quick_sort(self,left,right):
        if left<right:
            pivot = self.partition_sort(left,right)
            self.quick_sort(left,pivot-1)
            self.quick_sort(pivot+1,right)








if __name__ == '__main__':
    sweet = Sweet(10)
    sweet.random_int()
    sweet.method_choice(sweet.quick_sort,0,sweet.arrlen-1)
